<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<s:if test="updateResult !=0 ">
<script>
opener.location.href="/Jangdolbaeng2/productManager/productManager.action";
window.close();
</script>
</s:if>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- css 로드 -->
<link rel="stylesheet" type="text/css" href="/Jangdolbaeng2/css/seller/skin/Default/bootstrap.min.css" />
<link href="/Jangdolbaeng2/css/customer/common.css" rel="stylesheet">
<script type="text/javascript" src="/Jangdolbaeng2/js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="/Jangdolbaeng2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/Jangdolbaeng2/js/holder.js"></script>
<title>상품 수정</title>
</head>
<body>
	<div class="container">
		<!-- 상품 수정  -->
		<form action="updateProduct" method="post" enctype="multipart/form-data">
			<input type="hidden" name="product.shop_seq" value="${shop_seq}">
			<input type="hidden" name="product.product_seq" value="${product.product_seq}">
			<input type="hidden" name="imageIndex1" class="imageIndex1" value="false">	
			<input type="hidden" name="imageIndex2" class="imageIndex2" value="false">	
			<table class="table table-striped" style="width: 1100px">
				<tr>
					<th colspan="2" class="text-left"><span
						class="glyphicon glyphicon-share-alt"></span>&nbsp;&nbsp;<a>상품	수정</a></th>
				</tr>
				<tr>
					<td></td>
				</tr>
				<tr>
					<th>상품명</th>
					<td><input type="text" class="form-control"
						name="product.product_name" value="${product.product_name}"></td>
				</tr>
				<tr>
					<th>상품 카테고리</th>
					<td><select name='product.product_category'
						class="form-control">
							<s:iterator value="categoryMap" var="keys">
								<s:if test="%{#session.shop_category==#keys.key}">
									<option style="background: aqua;" selected="selected"
										value='<s:property value="key"/>'><s:property
											value="value" />
								</s:if>
								<s:else>
									<option value='<s:property value="key"/>'><s:property
											value="value" />
								</s:else>
							</s:iterator>
					</select></td>
				<tr>
					<th>상품가격(원)</th>
					<td><input type="text" class="form-control"
						name="product.product_price" value="${product.product_price}"></td>
				<tr>
					<th>기본 사진</th>
					<td><input type="file" name="uploads" id='imgInp0'></td>
				<tr>
					<th colspan="2"><img style="width: 220px; height: 150px"
						id='preview0'></th>
				<tr>
					<th>기본 상품정보</th>
					<td><input type="text" class="form-control"
						name='product.product_info1' value="${product.product_info1}"></td>
				<tr>
					<th>상세 사진</th>
					<td><input type="file" name="uploads" id='imgInp1'></td>
				<tr>
					<th colspan="2"><img id='preview1'
						style="width: 1000px; height: auto;"></th>
				<tr>
					<th>상품정보</th>
					<td><textarea class="form-control" rows="5"
							name="product.product_info2">${product.product_info2}</textarea></td>
				<tr>
					<th colspan="2" class="text-center"><input type="submit"
						class="btn btn-primary btn" value="수정"></th>
				</tr>
			</table>
			<br>
		</form>
	</div>
	<script type="text/javascript">
	$(document).ready(function(){
		$('#preview0').attr('src','data:image/jpeg;base64,${product.product_image1}');
		$('#preview1').attr('src','data:image/jpeg;base64,${product.product_image2}');
	});
		//image 파일 업로드 함수 
		function readURL(input,index) {
			if (input.files && input.files[0]) {
				var reader = new FileReader();
				reader.onload = function(e) {
					$('#preview'+index).attr('src', e.target.result);
					$('#preview'+index).removeClass('hidden');
				}
				reader.readAsDataURL(input.files[0]);
			}			
				if(index==1)
					$(".imageIndex2").val('true');
				else
					$(".imageIndex1").val('true');		
			
		}
		
		// 리스너 배열
		var indexArray = [1,2];
		
		//image 미리보기 리스너	
		$.each(indexArray,function(index){			
			$("#imgInp"+index).change(function() {				
				readURL(this,index);});			
		});
		function isEven(n){			
			return (n%2)==0 ? true : false;
		}		
	</script>
</body>
</html>